package org.focusj.scala.colls

object FoldFunction {
    def seqToString(seq: Seq[Char]) = {
        seq.foldLeft("")(_ + _)
    }

    def seqLength(seq: Seq[Char]) = {
        seq.foldLeft(0)((r, _) => r + 1)
    }

    def average(seq: Seq[Int]) = {
        seq.foldLeft(0)(_ + _) / seq.foldLeft(0)((r, _) => r + 1)
    }

    def sum(arr: Array[Int]) = {
        arr /*Array*/ .foldLeft(0)(_ + _)
    }

    def main(args: Array[String]) {
        val arr = Array(0, 1, 2, 3, 4, 5, 6, 7)
        println(sum(arr))
    }
}